package com.whut.mobilesafe.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.whut.mobilesafe.R;
import com.whut.mobilesafe.utils.PrefUtils;

public class Step3Activity extends BaseStepActivity {

    private EditText etSafePhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup3);
        etSafePhone = (EditText) findViewById(R.id.et_safe_phone);
        String safePhone = PrefUtils.getString(this, "safe_phone");
        etSafePhone.setText(safePhone);
    }

    //当点击了选择联系人的按钮之后，提到选择联系人页面。结束之后，回显到etSafePhone
    public void selectContract(View view) {
        startActivityForResult(new Intent(getApplicationContext(), ContractActivity.class), 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null) {
            String phone = data.getStringExtra("phone");
            phone = phone.replaceAll(" ","").replaceAll("-","");
            etSafePhone.setText(phone);
        }
    }

    @Override
    public void showNext() {
        String phone = etSafePhone.getText().toString();
        if (!TextUtils.isEmpty(phone)) {
            PrefUtils.setString(getApplicationContext(), "safe_phone", phone);

            startActivity(new Intent(getApplicationContext(), Step4Activity.class));
            finish();
            overridePendingTransition(R.anim.anim_right_in, R.anim.anim_right_out);
        } else {
            Toast.makeText(this, "安全号码不能为空", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void showPrevious() {
        startActivity(new Intent(getApplicationContext(), Step2Activity.class));
        finish();
        overridePendingTransition(R.anim.anim_left_in, R.anim.anim_left_out);
    }


}
